///*
// * Copyright (c) 2022, OUXIAOLONG. All rights reserved.
// *
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// *     http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// */
//package com.examples.springboot.jpa;
//
//import java.util.HashMap;
//import java.util.Map;
//
//import javax.persistence.EntityManagerFactory;
//import javax.sql.DataSource;
//
//import org.eclipse.persistence.config.BatchWriting;
//import org.eclipse.persistence.config.CacheType;
//import org.eclipse.persistence.config.PersistenceUnitProperties;
//import org.eclipse.persistence.logging.SessionLog;
//import org.modelmapper.ModelMapper;
//import org.springframework.beans.factory.ObjectProvider;
//import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration;
//import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.boot.jdbc.DataSourceBuilder;
//import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.core.env.Environment;
//import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
//import org.springframework.orm.jpa.JpaTransactionManager;
//import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
//import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter;
//import org.springframework.orm.jpa.vendor.Database;
//import org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect;
//import org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter;
//import org.springframework.transaction.PlatformTransactionManager;
//import org.springframework.transaction.annotation.EnableTransactionManagement;
//import org.springframework.transaction.jta.JtaTransactionManager;
//
//@Configuration(proxyBeanMethods = true)
//@EnableTransactionManagement
////@PropertySource("classpath:application.properties")
//@EnableJpaRepositories("com.examples.springboot.jpa.repository")
//public class EclipseLinkJpaConfiguration extends JpaBaseConfiguration {
//
//  protected EclipseLinkJpaConfiguration(DataSource dataSource, JpaProperties properties,
//    ObjectProvider<JtaTransactionManager> jtaTransactionManager) {
//    super(dataSource, properties, jtaTransactionManager);
//  }
//
//  @Bean
//  public EclipseLinkJpaDialect eclipseLinkJpaDialect() {
//     return new EclipseLinkJpaDialect();
//  }
//
//  @Override
//  protected AbstractJpaVendorAdapter createJpaVendorAdapter() {
//    return new EclipseLinkJpaVendorAdapter();
//  }
//
//  @Override
//  protected Map<String, Object> getVendorProperties() {
//    final Map<String, Object> ret = new HashMap<>();
//    ret.put(PersistenceUnitProperties.BATCH_WRITING, BatchWriting.JDBC);
//    return ret;
//  }
//
//  @Bean("entityManagerFactory")
//  public LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactory(
//    EntityManagerFactoryBuilder builder, DataSource dataSource,Environment env) {
//
//    return builder
//      .dataSource(dataSource)
//      .persistenceUnit("default-pu")
//      .packages(env.getProperty("basePackages",getClass().getPackage().getName()))
//      .properties(getEclipseLinkJpaProperties()).build();
//  }
//  
//  @Bean
//  public ModelMapper modelMapper() {
//      return new ModelMapper();
//  }
//
//  @Bean(name="mysqlDatasource")
//  @ConfigurationProperties(prefix="mysql.datasource")
//  public static DataSource mysqlDataSource() {
//      return DataSourceBuilder.create().build();
//  }
//
////  @Bean(name="sqliteDatasource")
////  @ConfigurationProperties(prefix="sqlite.datasource")
////  public static DataSource sqliteDataSource() {
////      return DataSourceBuilder.create().build();
////  }
//
//  @Bean
//  public static PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
//    final JpaTransactionManager transactionManager = new JpaTransactionManager();
//    transactionManager.setEntityManagerFactory(emf);
//    return transactionManager;
//  }
//
//  @Bean
//  @Primary
//  public static JpaProperties properties(Environment env) {
//    final JpaProperties jpaProperties = new JpaProperties();
//    jpaProperties.setShowSql(env.getProperty("jpa.show-sql", Boolean.class));
//    jpaProperties.setDatabase(Database.valueOf(env.getProperty("jpa.database")));
//    jpaProperties.setDatabasePlatform(env.getProperty("jpa.platform"));
//    return jpaProperties;
//  }
//
//  private static Map<String, ?> getEclipseLinkJpaProperties() {
//    final Map<String, Object> props = new HashMap<>();
//    // Add any JpaProperty you are interested in and is supported by your Database and JPA implementation
//    props.put(PersistenceUnitProperties.BATCH_WRITING, BatchWriting.JDBC);
//    props.put(PersistenceUnitProperties.LOGGING_LEVEL, SessionLog.SEVERE_LABEL);
//    props.put(PersistenceUnitProperties.WEAVING, Boolean.FALSE.toString());
//    props.put(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.CREATE_ONLY);
//    props.put(PersistenceUnitProperties.DDL_GENERATION_MODE, PersistenceUnitProperties.DDL_DATABASE_GENERATION);
//    props.put(PersistenceUnitProperties.CACHE_TYPE_DEFAULT, CacheType.NONE);
//    return props;
//  }
//}
